import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export default new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '*',
      redirect: '/login'
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('./views/pages/login/Login.vue')
    },
    {
      path: '/register',
      name: 'register',
      component: () => import('./views/pages/register/Register.vue')
    },
    {
      path: '/footer',
      name: 'footer',
      component: () => import('./views/pages/footer/Footer.vue'),
      redirect: '/footer/home',
      children: [ // 二级路由不要加‘ / ’
        {
          path: 'home',
          name: 'home',
          component: () => import('./views/pages/footer/components/home/Home.vue'),
          meta: {
            index: 0,
            requireAuth: false, // 当有这个字段的时候，我们就认为这个页面的路由需要登录权限
            footerShow: true // 导航栏显示与否
          }
        },
        {
          path: 'home/classifycontent/:id',
          name: 'classifycontent',
          component: () => import('./views/pages/footer/components/home/components/classifycontent/ClassifyContent.vue'),
          meta: {
            requireAuth: false, // 当有这个字段的时候，我们就认为这个页面的路由需要登录权限
            footerShow: true
          }
        },
        {
          path: 'home/seckillcontent',
          name: 'seckillcontent',
          component: () => import('./views/pages/footer/components/home/components/seckillcontent/SeckillContent.vue'),
          meta: {
            requireAuth: false, // 当有这个字段的时候，我们就认为这个页面的路由需要登录权限
            footerShow: true
          }
        },
        {
          path: 'home/dailycontent/:id',
          name: 'dailycontent',
          component: () => import('./views/pages/footer/components/home/components/dailycontent/DailyContent.vue'),
          meta: {
            requireAuth: false, // 当有这个字段的时候，我们就认为这个页面的路由需要登录权限
            footerShow: false
          }
        },
        {
          path: 'home/details/:id',
          name: 'details',
          component: () => import('./views/pages/footer/components/home/components/details/Details.vue'),
          meta: {
            requireAuth: false, // 当有这个字段的时候，我们就认为这个页面的路由需要登录权限
            footerShow: false
          }
        },
        {
          path: 'list',
          name: 'list',
          component: () => import('./views/pages/footer/components/list/List.vue'),
          meta: {
            index: 1,
            requireAuth: false, // 当有这个字段的时候，我们就认为这个页面的路由需要登录权限
            footerShow: true
          }
        },
        {
          path: 'search',
          name: 'search',
          component: () => import('./views/pages/footer/components/search/Search.vue'),
          meta: {
            index: 2,
            requireAuth: false, // 当有这个字段的时候，我们就认为这个页面的路由需要登录权限
            footerShow: true
          }
        },
        {
          path: 'cart',
          name: 'cart',
          component: () => import('./views/pages/footer/components/cart/Cart.vue'),
          meta: {
            index: 3,
            requireAuth: true, // 当有这个字段的时候，我们就认为这个页面的路由需要登录权限
            footerShow: true
          }
        },
        {
          path: 'mine',
          name: 'mine',
          component: () => import('./views/pages/footer/components/mine/Mine.vue'),
          meta: {
            index: 4,
            requireAuth: true, // 当有这个字段的时候，我们就认为这个页面的路由需要登录权限
            footerShow: true
          }
        }
      ]
    }
  ],
  // 滚动行为
  scrollBehavior (to, from, savedPosition) { // scrollBehavior 方法接收 to 和 from 路由对象。第三个参数 savedPosition 当且仅当 popstate 导航 (通过浏览器的 前进/后退 按钮触发) 时才可用。
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
  }
})
